package website.haicheng.core.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import website.haicheng.core.config.properties.SnowflakeProperties;

/**
 * @description: 雪花算法
 * @author: 582895699@qq.com
 * @time: 2021/3/4 下午 09:41
 */
@Component
public class IdService {

    @Autowired
    private SnowflakeProperties snowflakeProperties;

    public long nextId() {
        Snowflake snowflake = IdUtil.getSnowflake(snowflakeProperties.getWorkerId(), snowflakeProperties.getDataCenterId());
        return snowflake.nextId();
    }
}
